from typing import List

from ninja import Router, Query
from ninja.pagination import paginate

from apps.manager.water_card_record.schema import WaterCardRecordResponseSchema, WaterCardRecordFilterSchema
from models.models import WaterCardRecord
from utils.auth import ManagerAuthBearer
from utils.decorators import handle_exception
from utils.paginations import MyPagination

manager_water_card_record_router = Router(tags=["水卡记录"], auth=ManagerAuthBearer())


@manager_water_card_record_router.get("/water_card_records", summary="水卡记录列表",
                                      response=List[WaterCardRecordResponseSchema])
@handle_exception("获取水卡记录列表失败")
@paginate(MyPagination)
def get_water_card_records(request, filters: WaterCardRecordFilterSchema = Query(...), is_total=True):
    """
    获取水卡记录列表
    """
    records = WaterCardRecord.objects.all()
    records = filters.filter(records)
    return records
